// tabble gallery
document.querySelectorAll("table:has(img)").forEach(function (item) {
	item.classList.add("nexmoe-album");
});

// search
function search() {
	window.open(
		document.querySelector("#search_form").getAttribute("action_e") +
			" " +
			document.querySelector("#search_value").value
	);
	return false;
}

// catalog
document.querySelectorAll("a.toc-link").forEach(function (item) {
	item.addEventListener("click", function (ev) {
		ev.preventDefault();
		let title = this.getAttribute("href");
		window.scroll({
			top: document.querySelector(decodeURI(title)).offsetTop - 24,
			behavior: "smooth",
		});
	});
});

document.addEventListener("copy", function () {
	if (!window.copyTip) {
		return;
	}
	var sel = document.getSelection();
	var ele = document.createElement("div");
	ele.innerHTML =
		'<div style="position: fixed;opacity: 0;white-space: pre;">' +
		sel +
		"\n\n" +
		window.copyTip.replaceAll("%url", document.location.href) +
		" </div>";
	document.body.appendChild(ele);
	sel.selectAllChildren(ele);
	setTimeout(function () {
		document.body.removeChild(ele);
	});
});

function imgOnError(_this) {
	_this.src = ``;
	_this.onerror = null;
}

document
	.querySelectorAll(".nexmoe-post-cover.absolute")
	.forEach(function (item) {
		item.style.minHeight = item.childNodes[3].clientHeight + "px";
	});
